<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: SimpleBattery Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00193.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-types">Protected Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pro-attribs">Protected Attributes</a> &#124;
<a href="#pri-methods">Private Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">SimpleBattery Class Reference<div class="ingroups"><a class="el" href="a00530.html">Power consumption - Classes using/defining power consumption</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="SimpleBattery" --><!-- doxytag: inherits="BaseBattery" -->
<p>A simple linear model of battery consumption.  
 <a href="a00193.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="a00487_source.html">SimpleBattery.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for SimpleBattery:</div>
<div class="dyncontent">
<div class="center"><img src="a00997.png" border="0" usemap="#SimpleBattery_inherit__map" alt="Inheritance graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for SimpleBattery:</div>
<div class="dyncontent">
<div class="center"><img src="a00998.png" border="0" usemap="#SimpleBattery_coll__map" alt="Collaboration graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>

<p><a href="a00999.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a02f43017e7f375fb12a3299f929f99d3">initialize</a> (int)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Basic initialization for all modules.  <a href="#a02f43017e7f375fb12a3299f929f99d3"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a6741c08be8212fe0fe2786285157b991"></a><!-- doxytag: member="SimpleBattery::handleMessage" ref="a6741c08be8212fe0fe2786285157b991" args="(cMessage *)" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><b>handleMessage</b> (cMessage *)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#aad95dbfe21ea8354b02af1e9b4d387f7">handleHostState</a> (const <a class="el" href="a00098.html">HostState</a> &amp;state)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Called whenever the hosts state changes.  <a href="#aad95dbfe21ea8354b02af1e9b4d387f7"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a06b1ab5eb89e7cf72c0660eb5ed68f31"></a><!-- doxytag: member="SimpleBattery::finish" ref="a06b1ab5eb89e7cf72c0660eb5ed68f31" args="()" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><b>finish</b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="abb7866a326788b64466534c95ccb2b52"></a><!-- doxytag: member="SimpleBattery::registerDevice" ref="abb7866a326788b64466534c95ccb2b52" args="(const std::string &amp;name, int numAccounts)" -->
virtual int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#abb7866a326788b64466534c95ccb2b52">registerDevice</a> (const std::string &amp;name, int numAccounts)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Registers a power device by creating a new <a class="el" href="a00084.html" title="per-device/per-account record of battery consumption, is passed to BatteryStats on finish()...">DeviceEntry</a> for it. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aae7228c50e302f9f30eea0f1e69ba38b"></a><!-- doxytag: member="SimpleBattery::draw" ref="aae7228c50e302f9f30eea0f1e69ba38b" args="(int drainID, DrawAmount &amp;amount, int activity)" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#aae7228c50e302f9f30eea0f1e69ba38b">draw</a> (int drainID, <a class="el" href="a00087.html">DrawAmount</a> &amp;amount, int activity)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Draws either a certain amount of energy in mWs or a defined current in mA over time, depending on passed <a class="el" href="a00087.html" title="Defines the amount of power drawn by a device from a power source.">DrawAmount</a>. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a3e92cb2ebfbcd0879279f45ac03a5111"></a><!-- doxytag: member="SimpleBattery::getState" ref="a3e92cb2ebfbcd0879279f45ac03a5111" args="() const " -->
virtual <a class="el" href="a00098.html#a5002302e0f07bbd982c6e5d65eaa9c3c">HostState::States</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a3e92cb2ebfbcd0879279f45ac03a5111">getState</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Current state of the battery. <br/></td></tr>
<tr><td colspan="2"><div class="groupHeader">State-of-charge interface</div></td></tr>
<tr><td colspan="2"><div class="groupText"><p>Other host modules should use these interfaces to obtain the state-of-charge of the battery. Do NOT use <a class="el" href="a00032.html" title="residual capacity of battery">BatteryState</a> interfaces, which should be used only by Battery Stats modules. </p>
</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa0439bde80704c4346bc423da73bf789"></a><!-- doxytag: member="SimpleBattery::getVoltage" ref="aa0439bde80704c4346bc423da73bf789" args="() const " -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#aa0439bde80704c4346bc423da73bf789">getVoltage</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">get voltage (future support for non-voltage regulated h/w <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a0c2eeb0db29dfd5e519ff47f313ba9aa"></a><!-- doxytag: member="SimpleBattery::estimateResidualRelative" ref="a0c2eeb0db29dfd5e519ff47f313ba9aa" args="() const " -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a0c2eeb0db29dfd5e519ff47f313ba9aa">estimateResidualRelative</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">current state of charge of the battery, relative to its rated nominal capacity [0..1] <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="acebb3063d673fb8e96c72729ef3a3a56"></a><!-- doxytag: member="SimpleBattery::estimateResidualAbs" ref="acebb3063d673fb8e96c72729ef3a3a56" args="() const " -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#acebb3063d673fb8e96c72729ef3a3a56">estimateResidualAbs</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">current state of charge of the battery (mW-s) <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-types"></a>
Protected Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a2027a9cfdf410e246a3cb90acbfad6dd">msgType</a> { <b>AUTO_UPDATE</b>, 
<b>PUBLISH</b>
 }</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Self message kinds used by the battery. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a86c19e96a41b6edd8cce5f7da782966a"></a><!-- doxytag: member="SimpleBattery::deductAndCheck" ref="a86c19e96a41b6edd8cce5f7da782966a" args="()" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><b>deductAndCheck</b> ()</td></tr>
<tr><td colspan="2"><h2><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a713465d20e40c275f105d9cdff32b3f3"></a><!-- doxytag: member="SimpleBattery::numDevices" ref="a713465d20e40c275f105d9cdff32b3f3" args="" -->
int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a713465d20e40c275f105d9cdff32b3f3">numDevices</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">The maximum amount of different power drawing devices. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="adf9aa194bb0405e0d1d504a2f4e2562a"></a><!-- doxytag: member="SimpleBattery::resolution" ref="adf9aa194bb0405e0d1d504a2f4e2562a" args="" -->
simtime_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#adf9aa194bb0405e0d1d504a2f4e2562a">resolution</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Debit battery at least once every resolution seconds. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="af47d0bb558d32ae4c079feec825a301f"></a><!-- doxytag: member="SimpleBattery::timeout" ref="af47d0bb558d32ae4c079feec825a301f" args="" -->
cMessage *&#160;</td><td class="memItemRight" valign="bottom"><b>timeout</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a7ac70c949d5974651eb5c669f10352d9"></a><!-- doxytag: member="SimpleBattery::residualVec" ref="a7ac70c949d5974651eb5c669f10352d9" args="" -->
cOutVector&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a7ac70c949d5974651eb5c669f10352d9">residualVec</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Ouput vector tracking the residual capacity. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a1667f1336167e09b40dc3ab3b94f05d9"></a><!-- doxytag: member="SimpleBattery::devices" ref="a1667f1336167e09b40dc3ab3b94f05d9" args="" -->
<a class="el" href="a00084.html">DeviceEntry</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a1667f1336167e09b40dc3ab3b94f05d9">devices</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Array of different power consuming devices. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aca990f2e71c484694cb93bf2fe5cf29c"></a><!-- doxytag: member="SimpleBattery::registeredDevices" ref="aca990f2e71c484694cb93bf2fe5cf29c" args="" -->
int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#aca990f2e71c484694cb93bf2fe5cf29c">registeredDevices</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Amount of currently registered devices. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a1cd5c7fa6c929f92176c2280074bc721"></a><!-- doxytag: member="SimpleBattery::lastUpdateTime" ref="a1cd5c7fa6c929f92176c2280074bc721" args="" -->
simtime_t&#160;</td><td class="memItemRight" valign="bottom"><b>lastUpdateTime</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a31ed3863dd9803577d59dfa8952b1d72"></a><!-- doxytag: member="SimpleBattery::host" ref="a31ed3863dd9803577d59dfa8952b1d72" args="" -->
cModule *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a31ed3863dd9803577d59dfa8952b1d72">host</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Pointer to host module. <br/></td></tr>
<tr><td colspan="2"><div class="groupHeader">battery parameters</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a05d65f8b333b68eec48de0888f68261c"></a><!-- doxytag: member="SimpleBattery::capmAh" ref="a05d65f8b333b68eec48de0888f68261c" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a05d65f8b333b68eec48de0888f68261c">capmAh</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Actual capacity. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a318d762eb5c65237eb9aca0bf0e6d880"></a><!-- doxytag: member="SimpleBattery::nominalCapmAh" ref="a318d762eb5c65237eb9aca0bf0e6d880" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a318d762eb5c65237eb9aca0bf0e6d880">nominalCapmAh</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Nominal capacity. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aac296663af4d156e5b31f868abb5f7b7"></a><!-- doxytag: member="SimpleBattery::voltage" ref="aac296663af4d156e5b31f868abb5f7b7" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#aac296663af4d156e5b31f868abb5f7b7">voltage</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Voltage. <br/></td></tr>
<tr><td colspan="2"><div class="groupHeader">publishing of capacity to BatteryStats via the BB.</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ad7d03f71f85f952de696f906a5f16e34"></a><!-- doxytag: member="SimpleBattery::publish" ref="ad7d03f71f85f952de696f906a5f16e34" args="" -->
cMessage *&#160;</td><td class="memItemRight" valign="bottom"><b>publish</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a134a4882fa54badf6ac61bf7ca85c40b"></a><!-- doxytag: member="SimpleBattery::publishDelta" ref="a134a4882fa54badf6ac61bf7ca85c40b" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><b>publishDelta</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac6a51f675a5ff7cd53c79a87a8a8396e"></a><!-- doxytag: member="SimpleBattery::publishTime" ref="ac6a51f675a5ff7cd53c79a87a8a8396e" args="" -->
simtime_t&#160;</td><td class="memItemRight" valign="bottom"><b>publishTime</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ad65a4502e96576b1e12332dbb19a1f3e"></a><!-- doxytag: member="SimpleBattery::batteryState" ref="ad65a4502e96576b1e12332dbb19a1f3e" args="" -->
<a class="el" href="a00032.html">BatteryState</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#ad65a4502e96576b1e12332dbb19a1f3e">batteryState</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Holds the state of the battery. <br/></td></tr>
<tr><td colspan="2"><div class="groupHeader">publish of host failure notification</div></td></tr>
<tr><td colspan="2"><div class="groupText"><p>everyone should subscribe to this </p>
</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a2ce6f955ec0e80f98ccbabfdc9d5d1f2"></a><!-- doxytag: member="SimpleBattery::hostState" ref="a2ce6f955ec0e80f98ccbabfdc9d5d1f2" args="" -->
<a class="el" href="a00098.html">HostState</a>&#160;</td><td class="memItemRight" valign="bottom"><b>hostState</b></td></tr>
<tr><td colspan="2"><div class="groupHeader">INTERNAL state</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a167d1f32b5590266ae038c1ad9930d65"></a><!-- doxytag: member="SimpleBattery::capacity" ref="a167d1f32b5590266ae038c1ad9930d65" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><b>capacity</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a605d3891d36cfc5fe20908588ffff385"></a><!-- doxytag: member="SimpleBattery::nominalCapacity" ref="a605d3891d36cfc5fe20908588ffff385" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><b>nominalCapacity</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a161908772ca511a1ff0bac0c171b1748"></a><!-- doxytag: member="SimpleBattery::residualCapacity" ref="a161908772ca511a1ff0bac0c171b1748" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><b>residualCapacity</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a7f84316e88869a105abb59205cec3c13"></a><!-- doxytag: member="SimpleBattery::lastPublishCapacity" ref="a7f84316e88869a105abb59205cec3c13" args="" -->
double&#160;</td><td class="memItemRight" valign="bottom"><b>lastPublishCapacity</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a17e06cb38be96647528fa58ba7457f00"></a><!-- doxytag: member="SimpleBattery::lifetime" ref="a17e06cb38be96647528fa58ba7457f00" args="" -->
simtime_t&#160;</td><td class="memItemRight" valign="bottom"><b>lifetime</b></td></tr>
<tr><td colspan="2"><h2><a name="pri-methods"></a>
Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab25dfae170bbde8e03ea66240b1f2e7f"></a><!-- doxytag: member="SimpleBattery::SimpleBattery" ref="ab25dfae170bbde8e03ea66240b1f2e7f" args="(const SimpleBattery &amp;)" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#ab25dfae170bbde8e03ea66240b1f2e7f">SimpleBattery</a> (const <a class="el" href="a00193.html">SimpleBattery</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Copy constructor is not allowed. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8cc3e80734e33d25d753ba27b06a1919"></a><!-- doxytag: member="SimpleBattery::operator=" ref="a8cc3e80734e33d25d753ba27b06a1919" args="(const SimpleBattery &amp;)" -->
<a class="el" href="a00193.html">SimpleBattery</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00193.html#a8cc3e80734e33d25d753ba27b06a1919">operator=</a> (const <a class="el" href="a00193.html">SimpleBattery</a> &amp;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Assignment operator is not allowed. <br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>A simple linear model of battery consumption. </p>
<p>See SimpleBattery.ned for parameters</p>
<p>Simple Battery receives DrawMsg's from one or more devices, updates residual capacity (total current * voltage * time), publishes <a class="el" href="a00098.html" title="HostState is published by the battery to announce host failure.">HostState</a> notification on battery depletion, and provides time series and summary information to Battery Stats module.</p>
<dl class="author"><dt><b>Author:</b></dt><dd>Laura Marie Feeney </dd>
<dd>
Karl Wessel (port for MiXiM) </dd></dl>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="aad95dbfe21ea8354b02af1e9b4d387f7"></a><!-- doxytag: member="SimpleBattery::handleHostState" ref="aad95dbfe21ea8354b02af1e9b4d387f7" args="(const HostState &amp;state)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void SimpleBattery::handleHostState </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="a00098.html">HostState</a> &amp;&#160;</td>
          <td class="paramname"><em>state</em></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Called whenever the hosts state changes. </p>
<p>Default implementation of this method throws an error whenever the host state changes and the "notAffectedbyHostState" variable is not explicitly set. This is because every module of a host has to make sure to react well to changes in the host state. Or it has to explicitly set its parameter "notAffectedbyHostState" to true. </p>

<p>Reimplemented from <a class="el" href="a00027.html#a44220aa650488eee8ad121f8bc599265">BaseModule</a>.</p>
<div class="fragment"><pre class="fragment">{
  <span class="comment">//does nothing yet</span>
}
</pre></div>
</div>
</div>
<a class="anchor" id="a02f43017e7f375fb12a3299f929f99d3"></a><!-- doxytag: member="SimpleBattery::initialize" ref="a02f43017e7f375fb12a3299f929f99d3" args="(int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void SimpleBattery::initialize </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>stage</em></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Basic initialization for all modules. </p>
<p>Subscription should be in stage==0, and firing notifications in stage==1 or later.</p>
<p>NOTE: You have to call this in the <a class="el" href="a00193.html#a02f43017e7f375fb12a3299f929f99d3" title="Basic initialization for all modules.">initialize()</a> function of the inherited class! </p>

<p>Reimplemented from <a class="el" href="a00027.html#a03030e439aaf030c83da6e71e8be2f80">BaseModule</a>.</p>

<p>References <a class="el" href="a00193.html#ad65a4502e96576b1e12332dbb19a1f3e">batteryState</a>, <a class="el" href="a00193.html#a05d65f8b333b68eec48de0888f68261c">capmAh</a>, <a class="el" href="a00033.html#adc69f67560c724bb41dbd4c5dfd81df0">BatteryStats::catBatteryStateSignal</a>, <a class="el" href="a00027.html#a0d89757df3cc2bf55649eee85aad6402">BaseModule::catHostStateSignal</a>, <a class="el" href="a00193.html#a1667f1336167e09b40dc3ab3b94f05d9">devices</a>, <a class="el" href="a00027.html#aabf0226159b22b46e70031fd3bb3b1b2">BaseModule::findHost()</a>, <a class="el" href="a00193.html#a31ed3863dd9803577d59dfa8952b1d72">host</a>, <a class="el" href="a00201.html#aa01f017b96087bc252445206777e0080">simsignalwrap_t::initialize()</a>, <a class="el" href="a00193.html#a318d762eb5c65237eb9aca0bf0e6d880">nominalCapmAh</a>, <a class="el" href="a00193.html#a713465d20e40c275f105d9cdff32b3f3">numDevices</a>, <a class="el" href="a00193.html#aca990f2e71c484694cb93bf2fe5cf29c">registeredDevices</a>, <a class="el" href="a00193.html#a7ac70c949d5974651eb5c669f10352d9">residualVec</a>, <a class="el" href="a00193.html#adf9aa194bb0405e0d1d504a2f4e2562a">resolution</a>, <a class="el" href="a00032.html#aaa9af946d2a8a122b13d9eb16e97fc15">BatteryState::set()</a>, <a class="el" href="a00098.html#a403e773f87d00a6c66f3f017441de752">HostState::set()</a>, and <a class="el" href="a00193.html#aac296663af4d156e5b31f868abb5f7b7">voltage</a>.</p>
<div class="fragment"><pre class="fragment">                                        {
  <a class="code" href="a00193.html#a02f43017e7f375fb12a3299f929f99d3" title="Basic initialization for all modules.">BaseBattery::initialize</a>(stage);

  <span class="keywordflow">if</span> (stage == 0) {
    <a class="code" href="a00193.html#aac296663af4d156e5b31f868abb5f7b7" title="Voltage.">voltage</a> = par(<span class="stringliteral">&quot;voltage&quot;</span>);
    <a class="code" href="a00193.html#a318d762eb5c65237eb9aca0bf0e6d880" title="Nominal capacity.">nominalCapmAh</a> = par(<span class="stringliteral">&quot;nominal&quot;</span>);
    <span class="keywordflow">if</span> (<a class="code" href="a00193.html#a318d762eb5c65237eb9aca0bf0e6d880" title="Nominal capacity.">nominalCapmAh</a> &lt;= 0) {
      error(<span class="stringliteral">&quot;invalid nominal capacity value&quot;</span>);
    }
    <a class="code" href="a00193.html#a05d65f8b333b68eec48de0888f68261c" title="Actual capacity.">capmAh</a> = par(<span class="stringliteral">&quot;capacity&quot;</span>);

    <span class="comment">// Publish capacity to BatteryStats every publishTime (if &gt; 0) and</span>
    <span class="comment">// whenever capacity has changed by publishDelta (if &lt; 100%).</span>
    publishTime = 0;
    publishTime = par(<span class="stringliteral">&quot;publishTime&quot;</span>);
    <span class="keywordflow">if</span> (publishTime &gt; 0) {
      publish = <span class="keyword">new</span> cMessage(<span class="stringliteral">&quot;publish&quot;</span>, PUBLISH);
      publish-&gt;setSchedulingPriority(2000);
      scheduleAt(simTime() + publishTime, publish);
    }
    publishDelta = 1;
    publishDelta = par(<span class="stringliteral">&quot;publishDelta&quot;</span>);
    <span class="keywordflow">if</span> (publishDelta &lt; 0 || publishDelta &gt; 1) {
      error(<span class="stringliteral">&quot;invalid publishDelta value&quot;</span>);
    }

    <a class="code" href="a00193.html#adf9aa194bb0405e0d1d504a2f4e2562a" title="Debit battery at least once every resolution seconds.">resolution</a> = par(<span class="stringliteral">&quot;resolution&quot;</span>);

    debugEV&lt;&lt; <span class="stringliteral">&quot;capacity = &quot;</span> &lt;&lt; <a class="code" href="a00193.html#a05d65f8b333b68eec48de0888f68261c" title="Actual capacity.">capmAh</a> &lt;&lt; <span class="stringliteral">&quot;mA-h (nominal = &quot;</span> &lt;&lt; <a class="code" href="a00193.html#a318d762eb5c65237eb9aca0bf0e6d880" title="Nominal capacity.">nominalCapmAh</a> &lt;&lt;
    <span class="stringliteral">&quot;) at &quot;</span> &lt;&lt; <a class="code" href="a00193.html#aac296663af4d156e5b31f868abb5f7b7" title="Voltage.">voltage</a> &lt;&lt; <span class="stringliteral">&quot;V&quot;</span> &lt;&lt; std::endl;
    debugEV &lt;&lt; <span class="stringliteral">&quot;publishDelta = &quot;</span> &lt;&lt; publishDelta * 100 &lt;&lt; <span class="stringliteral">&quot;%, publishTime = &quot;</span>
    &lt;&lt; publishTime &lt;&lt; <span class="stringliteral">&quot;s, resolution = &quot;</span> &lt;&lt; <a class="code" href="a00193.html#adf9aa194bb0405e0d1d504a2f4e2562a" title="Debit battery at least once every resolution seconds.">resolution</a> &lt;&lt; <span class="stringliteral">&quot;sec&quot;</span>
    &lt;&lt; std::endl;

    capacity = <a class="code" href="a00193.html#a05d65f8b333b68eec48de0888f68261c" title="Actual capacity.">capmAh</a> * 60 * 60 * <a class="code" href="a00193.html#aac296663af4d156e5b31f868abb5f7b7" title="Voltage.">voltage</a>; <span class="comment">// use mW-sec internally</span>
    nominalCapacity = <a class="code" href="a00193.html#a318d762eb5c65237eb9aca0bf0e6d880" title="Nominal capacity.">nominalCapmAh</a> * 60 * 60 * <a class="code" href="a00193.html#aac296663af4d156e5b31f868abb5f7b7" title="Voltage.">voltage</a>;
    <a class="code" href="a00193.html#ad65a4502e96576b1e12332dbb19a1f3e" title="Holds the state of the battery.">batteryState</a> = <span class="keyword">new</span> <a class="code" href="a00032.html" title="residual capacity of battery">BatteryState</a>(nominalCapacity);

    residualCapacity = lastPublishCapacity = capacity;

    lifetime = -1; <span class="comment">// -1 means not dead</span>

    <span class="comment">// DISable by default (use BatteryStats for data collection)</span>
    <a class="code" href="a00193.html#a7ac70c949d5974651eb5c669f10352d9" title="Ouput vector tracking the residual capacity.">residualVec</a>.disable();

    <a class="code" href="a00193.html#a7ac70c949d5974651eb5c669f10352d9" title="Ouput vector tracking the residual capacity.">residualVec</a>.setName(<span class="stringliteral">&quot;residualCapacity&quot;</span>);
    <a class="code" href="a00193.html#a7ac70c949d5974651eb5c669f10352d9" title="Ouput vector tracking the residual capacity.">residualVec</a>.record(residualCapacity);

    timeout = <span class="keyword">new</span> cMessage(<span class="stringliteral">&quot;auto-update&quot;</span>, AUTO_UPDATE);
    timeout-&gt;setSchedulingPriority(500);
    scheduleAt(simTime() + <a class="code" href="a00193.html#adf9aa194bb0405e0d1d504a2f4e2562a" title="Debit battery at least once every resolution seconds.">resolution</a>, timeout);

    <span class="comment">// publish battery depletion on hostStateCat</span>
    <span class="comment">// periodically publish residual capacity on batteryCat</span>
    <a class="code" href="a00193.html#a713465d20e40c275f105d9cdff32b3f3" title="The maximum amount of different power drawing devices.">numDevices</a> = hasPar(<span class="stringliteral">&quot;numDevices&quot;</span>) ? par(<span class="stringliteral">&quot;numDevices&quot;</span>) : 0;
    <span class="keywordflow">if</span> (<a class="code" href="a00193.html#a713465d20e40c275f105d9cdff32b3f3" title="The maximum amount of different power drawing devices.">numDevices</a> == 0) {
      EV &lt;&lt; <span class="stringliteral">&quot;Warning: no devices attached to battery\n&quot;</span>;
    }
    <a class="code" href="a00193.html#aca990f2e71c484694cb93bf2fe5cf29c" title="Amount of currently registered devices.">registeredDevices</a> = 0;

    <a class="code" href="a00193.html#a1667f1336167e09b40dc3ab3b94f05d9" title="Array of different power consuming devices.">devices</a> = <span class="keyword">new</span> <a class="code" href="a00084.html" title="per-device/per-account record of battery consumption, is passed to BatteryStats on finish()...">DeviceEntry</a>[<a class="code" href="a00193.html#a713465d20e40c275f105d9cdff32b3f3" title="The maximum amount of different power drawing devices.">numDevices</a>];
    lastUpdateTime = simTime();

    <a class="code" href="a00193.html#a31ed3863dd9803577d59dfa8952b1d72" title="Pointer to host module.">host</a> = <a class="code" href="a00027.html#aabf0226159b22b46e70031fd3bb3b1b2" title="Function to get a pointer to the host module.">findHost</a>();
  }
  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (stage == 1) {
    hostState.<a class="code" href="a00098.html#a403e773f87d00a6c66f3f017441de752" title="Sets the host state.">set</a>(HostState::ACTIVE);
    emit(<a class="code" href="a00027.html#a0d89757df3cc2bf55649eee85aad6402" title="Stores the category of the HostState.">catHostStateSignal</a>.<a class="code" href="a00201.html#aa01f017b96087bc252445206777e0080">initialize</a>(), &amp;hostState);

    <span class="keywordflow">if</span> (publishDelta &lt; 1 || publishTime&gt; 0 ) {
      <a class="code" href="a00193.html#ad65a4502e96576b1e12332dbb19a1f3e" title="Holds the state of the battery.">batteryState</a>-&gt;<a class="code" href="a00032.html#aaa9af946d2a8a122b13d9eb16e97fc15" title="Sets the residual capacity of battery (in mW-s).">set</a>(residualCapacity);
      emit(<a class="code" href="a00033.html#adc69f67560c724bb41dbd4c5dfd81df0" title="Signal for the BatteryStats.">BatteryStats::catBatteryStateSignal</a>.<a class="code" href="a00193.html#a02f43017e7f375fb12a3299f929f99d3" title="Basic initialization for all modules.">initialize</a>(), <a class="code" href="a00193.html#ad65a4502e96576b1e12332dbb19a1f3e" title="Holds the state of the battery.">batteryState</a>);
    }
    <span class="keywordflow">else</span> {
      <a class="code" href="a00033.html#adc69f67560c724bb41dbd4c5dfd81df0" title="Signal for the BatteryStats.">BatteryStats::catBatteryStateSignal</a>.<a class="code" href="a00201.html#aa01f017b96087bc252445206777e0080">initialize</a>();
    }
  }
}
</pre></div>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/power/battery/<a class="el" href="a00487_source.html">SimpleBattery.h</a></li>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/power/battery/SimpleBattery.cc</li>
</ul>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00193.html">SimpleBattery</a>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:33 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
